package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduForumLikeDTO;
import com.zenith.edu.po.vo.EduForumLikeVO;
import com.zenith.edu.service.EduForumLikeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/forum-like")
@Tag(name = "论坛点赞管理", description = "论坛点赞管理接口")
public class EduForumLikeController {
    
    @Autowired
    private EduForumLikeService eduForumLikeService;
    
    @SecurePostMapping(value = "createForumLike",roles = "ROLE_ADMIN",permission = "forum-like:create")
    @Operation(summary = "创建论坛点赞记录")
    public Result<EduForumLikeVO> createForumLike(@RequestBody EduForumLikeDTO dto) {
        EduForumLikeVO forumLikeVO = eduForumLikeService.createForumLike(dto);
        return Result.success(forumLikeVO);
    }
    
    @SecurePostMapping(value = "getForumLikeById",roles = "ROLE_ADMIN",permission = "forum-like:read")
    @Operation(summary = "根据ID获取论坛点赞记录详情")
    public Result<EduForumLikeVO> getForumLikeById(@PathVariable Long id) {
        EduForumLikeVO forumLikeVO = eduForumLikeService.getForumLikeById(id);
        if (forumLikeVO == null) {
            return Result.fail("论坛点赞记录不存在");
        }
        return Result.success(forumLikeVO);
    }
    
    @SecurePostMapping(value = "updateForumLike",roles = "ROLE_ADMIN",permission = "forum-like:update")
    @Operation(summary = "更新论坛点赞记录信息")
    public Result<EduForumLikeVO> updateForumLike(@RequestBody EduForumLikeDTO dto) {
        EduForumLikeVO forumLikeVO = eduForumLikeService.updateForumLike(dto);
        return Result.success(forumLikeVO);
    }
    
    @SecurePostMapping(value = "deleteForumLike",roles = "ROLE_ADMIN",permission = "forum-like:delete")
    @Operation(summary = "删除指定论坛点赞记录")
    public Result<Void> deleteForumLike(@PathVariable Long id) {
        boolean result = eduForumLikeService.deleteForumLike(id);
        if (!result) {
            return Result.fail("论坛点赞记录删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "getForumLikeList",roles = "ROLE_ADMIN",permission = "forum-like:read")
    @Operation(summary = "获取论坛点赞记录列表")
    public Result<List<EduForumLikeVO>> getForumLikeList() {
        List<EduForumLikeVO> forumLikeList = eduForumLikeService.getForumLikeList();
        return Result.success(forumLikeList);
    }
}